package cn.line5.seam.contexts;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.line5.seam.cache.ComponentCache;
import cn.line5.seam.cache.DBConfigCache;
import cn.line5.seam.cache.FilterCache;
import cn.line5.seam.cache.InterceptorCache;
import cn.line5.seam.cache.PageCache;
import cn.line5.seam.cache.UploadConfigCache;

/**
 * <h1>启动时监听类</h1> 启动时将按顺序加载数据库连接配置、文件上传配置、拦截器配置、组件配置、页面配置。 web.xml加入如下配置：<br/>
 * <I>&lt;listener&gt;<br/>
 * &lt;listener-class&gt;cn.line5.seam.context.ContextLoaderListener&lt;/
 * listener-class&gt;<br/>
 * &lt;/listener&gt;</I><br/>
 * 
 * @author Liu,Xiaojun
 * @since JDK1.6
 */
public class ContextLoaderListener implements ServletContextListener {
	private static final Logger log = LoggerFactory
			.getLogger(ContextLoaderListener.class);

	public void contextInitialized(ServletContextEvent event) {
		log.info("Welcome to the LINE5-SEAM!");
		new DBConfigCache(event.getServletContext().getInitParameter(
				"LSEAM_DB_CONFIG"));
		new UploadConfigCache(event.getServletContext().getInitParameter(
				"LSEAM_UPLOAD_CONFIG"));
		InterceptorCache.interceptorClass = (event.getServletContext()
				.getInitParameter("INTERCEPTOR_CLASS") != null && event
				.getServletContext().getInitParameter("INTERCEPTOR_CLASS")
				.length() > 0) ? event.getServletContext().getInitParameter(
				"INTERCEPTOR_CLASS") : InterceptorCache.interceptorClass;
		FilterCache.filterClass = (event.getServletContext().getInitParameter(
				"FILTER_CLASS") != null && event.getServletContext()
				.getInitParameter("FILTER_CLASS").length() > 0) ? event
				.getServletContext().getInitParameter("FILTER_CLASS")
				: FilterCache.filterClass;
		new ComponentCache();
		new PageCache(event.getServletContext());
	}

	public void contextDestroyed(ServletContextEvent event) {
	}
}